package com.ktwlrj.securitycenter.configs;

import com.ktwlrj.core.config.properties.AppProperty;
import com.ktwlrj.securitycenter.interceptor.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * 拦截器配置
 *
 * @author lisc
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    final private AppProperty property;

    @Autowired
    public WebMvcConfiguration(AppProperty property) {
        this.property = property;
    }

    @Bean
    AuthInterceptor getAuthInterceptor() {
        return new AuthInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> list = new ArrayList<>(property.getWhiteAuthList());
        registry.addInterceptor(getAuthInterceptor()).addPathPatterns("/**").excludePathPatterns(list);
        WebMvcConfigurer.super.addInterceptors(registry);
    }

}
